<template>
  <div class="box">
    <div class="header">
      <van-icon @click="toHome" class="home" size="30px" name="home-o" />
      <div class="logo"><img src="./images/1.webp" alt="" /></div>
      <van-icon class="search" size="30px" name="search" />
      <van-icon size="30px" class="cart" name="shopping-cart-o" />
    </div>
    <div class="baoyou">因疫情影响，部分地区无法配送公告</div>
    <div class="line"></div>
    <div class="address">
      <div class="name">
        <div>崔健</div>
        <div>默认</div>
      </div>
      <div class="center">
        <div class="phone">158****0997</div>
        <div>北京市昌平区北七家镇宏福苑南二区</div>
      </div>
      <div class="right">＞</div>
    </div>
    <div class="goods">
      <van-card
        v-for="(good, index) in detailArrayList"
        :key="good.skuId"
        :num="good.skuNum"
        tag="爆款"
        :price="good.orderPrice"
        :title="good.skuName"
        :thumb="good.imgUrl"
        :origin-price="index + 999"
      />
    </div>
    <div class="submit">
      <div class="left">应付:¥{{ totalPrice }}</div>
      <div class="right" @click="goPay">提交订单</div>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import { Card } from "vant";
import { reqTrade } from "@/api/order";

Vue.use(Card);
export default {
  name: "Trade",
  data() {
    return {
      detailArrayList: [],
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    // 获取数据
    async getData() {
      let res = await reqTrade();
      if (res.code == 200) {
        console.log(res.data);
        this.detailArrayList = res.data.detailArrayList;
      }
    },
    // 跳转到首页
    toHome() {
      this.$router.push("/home");
    },
    // 跳转到支付页
    goPay() {
      this.$router.push("/pay");
    },
  },
  computed: {
    totalPrice() {
      return this.detailArrayList.reduce((a, b) => {
        return a + b.orderPrice;
      }, 0);
    },
  },
};
</script>

<style lang="less" scoped>
.box {
  width: 100%;
  background-color: #f4f4f4;
  height: 100%;
  padding-bottom: 350px;
  .header {
    width: 100%;
    text-align: center;
    height: 38px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid#e8e8e8;
    background: #fafafa;
    position: fixed;
    top: 0;
    left: 0;
    .home {
      margin-left: 8px;
    }
    .cart {
      margin: 0 8px 0 14px;
    }
    .logo {
      flex: 1;
      height: 20px;
      width: 20px;
      margin-left: 50px;
      img {
        height: 16px;
      }
    }
  }
  .baoyou {
    margin-top: 35px;
    height: 35px;
    background: #fff8d8;
    line-height: 35px;
    padding-left: 14px;
    color: #f49128;
    font-size: 12px;
  }
  .line {
    background: url(//yanxuan-static.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/address-bg-67880192dc.png?imageView&type=webp) repeat-x;
    background-size: 25px 4px;
    height: 4px;
    margin-top: 12px;
  }
  .address {
    display: flex;
    font-size: 12px;
    background: #ffffff;
    height: 85px;
    align-items: center;
    margin-bottom: 12px;
    .name {
      height: 85px;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding-top: 20px;
      padding-left: 10px;
      box-sizing: border-box;
      width: 40px;
      background: #ffffff;
      div:nth-child(2) {
        font-size: 8px;
        color: red;
        border: 1.5px solid red;
      }
    }
    .center {
      flex: 1;
      height: 85px;
      display: flex;
      padding-left: 20px;
      box-sizing: border-box;
      flex-direction: column;
      justify-content: center;
    }
    .right {
      height: 85px;
      line-height: 95px;
      text-align: center;
      width: 40px;
      background-color: #ffffff;
    }
  }
  .submit {
    height: 40px;
    border: 1px solid #dddddd;
    width: 100%;
    position: fixed;
    z-index: 999;
    bottom: 0;
    right: 0;
    background-color: #ffffff;
    display: flex;
    justify-content: space-between;
    line-height: 40px;
    font-size: 14px;
    .left {
      padding-left: 20px;
      color: #e55257;
      font-weight: bold;
      font-size: 20px;
    }
    .right {
      width: 80px;
      background-color: #dd1a21;
      text-align: center;
      color: #faddde;
    }
  }
}
</style>
